Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emphasizing Error-Inducing Code Chunks for Text-Based Reporters #970

Merged
merged 15 commits into from
Oct 17, 2023

Conversation

umututku03
Copy link
Contributor

@umututku03 umututku03 commented Oct 6, 2023

Motivation and Context

PythonTA currently supports various types of reporters, including HTMLReporter (which generates an HTML file) and text-based reporters like PlainReporter and ColourReporter. The HTML-based reporter effectively highlights the sections that cause errors. However, there's an issue with the PlainReporter. It generates a .txt file without any highlighting, making it difficult to distinguish between the code with errors and other content. Additionally, ColourReporter inherits from PlainReporter, necessitating adjustments to maintain its existing functionality while addressing this highlighting concern.

Your Changes

Description:

I've overridden the PlainReporter._add_line method to incorporate an over-line character (Unicode 203E) beneath any section highlighted as an error. Additionally, I've overridden the ColourReporter._add_line method to ensure it inherits the functionality of PythonTaReporter._add_line. This change allows us to maintain the existing behavior of ColourReporter while addressing the required enhancements (notice that PlainReporter is the parent class of ColourReporter).

Type of change (select all that apply):

  • New feature (non-breaking change which adds functionality)
  • Refactoring (internal change to codebase, without changing functionality)

Testing

I did a lot of manual testings for this change. Below, I've included several screenshots showcasing the modifications I've implemented, along with corresponding comparisons across various types of reporters.

ColourReporter

image

PlainReporter

image

HTMLReporter

image

More examples

image image image image

Questions and Comments (if applicable)

Is it advisable to introduce an abstraction layer for text-based reporters? Considering the SOLID Principles we're currently studying in CSC207, it appears to align with the Dependency Inversion Principle. Would this interpretation accurately apply to our subject?

Checklist

  • I have performed a self-review of my own code.
  • I have verified that the CI tests have passed.
  • I have reviewed the test coverage changes reported on Coveralls.

@umututku03 umututku03 marked this pull request as ready for review October 6, 2023 23:42
@coveralls
Copy link
Collaborator

coveralls commented Oct 6, 2023

Pull Request Test Coverage Report for Build 6539593624

  • 21 of 21 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.03%) to 94.626%

Totals Coverage Status
Change from base Build 6459565236: 0.03%
Covered Lines: 3416
Relevant Lines: 3610

💛 - Coveralls

Copy link
Contributor

@david-yz-liu david-yz-liu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@umututku03 this is a great start. Some overall comments:

  1. Make sure to update the changelog (add this entry as an "enhancement").
  2. Right now the PlainReporter._add_line method is duplicating a substantial amount of code from the superclass _add_line method. The right way to think about this method is that it should first call the superclass method (to build an initial snippet), and then add an additional line of text after that snippet that contains the underlining characters.
  3. As a related point, right now you're using len(snippet) (and similar other code) to determine the amount of "pre-space" to use. Rather than doing that, you should calculate more precisely exactly how much space to be added without relying on the snippet at all! The implementation of _add_line_number gives you a starting point, as does the slice_.start value.
  4. I suspect if you make the change from (3), it will also fix the issue you're seeing with the ColorReporter. While you are correct that dependency injection and an intermediate layer "text reporter" parent class would be possible (with subclasses filling in the "underlining" functionality), in this case I suspect there's a simpler approach involving updating the PlainReporter._add_line method.

@umututku03 umututku03 marked this pull request as draft October 10, 2023 21:39
@umututku03 umututku03 marked this pull request as ready for review October 10, 2023 21:55
@david-yz-liu
Copy link
Contributor

@umututku03 great, please also do a merge from upstream master (you'll see there's a merge conflict in the Changelog, which is normal and a good opportunity for you to practice resolving merge conflicts).

python_ta/reporters/plain_reporter.py Outdated Show resolved Hide resolved
python_ta/reporters/plain_reporter.py Outdated Show resolved Hide resolved
python_ta/reporters/plain_reporter.py Outdated Show resolved Hide resolved
@david-yz-liu david-yz-liu merged commit 5f2d922 into pyta-uoft:master Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants